package com.shmilyou.dissertationmanagement.web;
/* Created with 岂止是一丝涟漪     530060499@qq.com    2019/3/15 */

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice
public class GlobalExceptionHandler {
    private final Logger log = LoggerFactory.getLogger(IndexController.class);

    @ExceptionHandler(value = Exception.class)
    public ModelAndView defaultErrorHandler(HttpServletRequest req, Exception e) {
        log.error(e.getLocalizedMessage(), e.getMessage());
        ModelAndView map = new ModelAndView();
        map.addObject("msg", e.getLocalizedMessage() + "<br>" + e.getMessage());
        map.setViewName("error");
        return map;
    }
}
